﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Web.UI.WebControls;

namespace PM.Web
{
    public partial class ServicesList : System.Web.UI.Page
    {
        public string TypeName = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Common.CheckUserOnline();
                if (string.IsNullOrEmpty(Request.QueryString["type"])) {
                    TypeName = "请修与投诉单列表";
                }
                else if (Request.QueryString["type"] == "1") {
                    TypeName = "请修单列表";
                }
                else if (Request.QueryString["type"] == "2")
                {
                    TypeName = "投诉单列表";
                }
                else {
                    TypeName = "参数错误，非法访问";
                    Response.End();
                }
                bindData();
            }
        }

        private void bindData()
        {
            DataAccess.PmData dal = new DataAccess.PmData();
            DataTable dt = new DataTable();
            if (Request.QueryString["type"] == "1")
            {
                dt = dal.GetRepairList(int.Parse(Session["CommId"].ToString()), int.Parse(Session["BuildId"].ToString()), int.Parse(Session["UnitId"].ToString()), int.Parse(Session["EmpId"].ToString()), string.Empty, null);
            }
            else if (Request.QueryString["type"] == "2")
            {
                dt = dal.GetComplaints(int.Parse(Session["CommId"].ToString()), int.Parse(Session["BuildId"].ToString()), int.Parse(Session["UnitId"].ToString()), int.Parse(Session["EmpId"].ToString()), string.Empty, null);
            }
            else
            {
                dt = dal.GetRepairAndComplaints(int.Parse(Session["CommId"].ToString()), int.Parse(Session["BuildId"].ToString()), int.Parse(Session["UnitId"].ToString()), int.Parse(Session["EmpId"].ToString()), string.Empty, null);
            }
            AspNetPager1.RecordCount = dt.Rows.Count;
            PagedDataSource pds = new PagedDataSource();
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            pds.DataSource = dt.DefaultView;
            this.repServicesList.DataSource = pds;
            this.repServicesList.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bindData();
        }
    }
}